import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;

import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.MultimediaInfo;

public class VideoDuration {

	public void getVideoDuration(String path) {

		if (path == null || "".equals(path)) {
			return;
		}

		Collection<File> files2 = FileUtils.listFiles(new File(path), new String[] { "wmv", "flv", "avi", "mp4" },
				true);
		File[] files = files2.toArray(new File[files2.size()]);
		Encoder encoder = new Encoder();
		MultimediaInfo multimediaInfo;

		long totalTime = 0L;
		long duration = 0L;

		for (int i = 0; i < files.length; i++) {
			try {
				multimediaInfo = encoder.getInfo(files[i]);
				duration = multimediaInfo.getDuration();
				totalTime += duration;
			} catch (EncoderException e) {
				e.printStackTrace();
			}
		}

		TimeZone.setDefault(TimeZone.getTimeZone("GMT+00:00")); // January 1, 1970, 00:00:00 GMT(can be found in
																// Date.class)
		Date date = new Date(totalTime);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
		System.out.println(simpleDateFormat.format(date) + "\t" + path);
	}

	public static void main(String[] args) {
		VideoDuration videoDuration = new VideoDuration();
		String tempPath="G:\\sp视频\\new\\框架\\javaSE";
		File file = new File(tempPath);
		File[] listFiles = file.listFiles();
		for (File file2 : listFiles) {
			if (file2.isDirectory()) {
				videoDuration.getVideoDuration(file2.getAbsolutePath());
			}
		}

	}
}